package org.rency.ues.domainservice.support;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.rency.ues.common.enums.EncryptType;
import org.rency.ues.dal.entity.DataHashDO;
import org.rency.ues.dal.entity.EncryptDataDO;

public class UesConverter {

	public static EncryptData convert(EncryptDataDO from){
		if(from == null){
			return null;
		}
		EncryptData en = new EncryptData();
		en.setCreateTime(from.getCreateTime());
		en.setEncryptData(from.getEncryptData());
		en.setEncryptKey(from.getEncryptKey());
		en.setEncryptType(EncryptType.get(from.getEncryptType()));
		en.setExpireTime(from.getExpireTime());
		en.setId(from.getId());
		en.setTicket(from.getTicket());
		en.setUpdateTime(from.getUpdateTime());
		en.setVersion(from.getVersion());
		return en;
	}
	
	public static EncryptDataDO convert(EncryptData en){
		if(en == null){
			return null;
		}
		EncryptDataDO to = new EncryptDataDO();
		to.setEncryptData(en.getEncryptData());
		to.setCreateTime(en.getCreateTime());
		to.setEncryptKey(en.getEncryptKey());
		to.setEncryptType(en.getEncryptType().getCode());
		to.setExpireTime(en.getExpireTime());
		to.setId(en.getId());
		to.setTicket(en.getTicket());
		to.setUpdateTime(en.getUpdateTime());
		to.setVersion(en.getVersion());
		return to;
	}
	
	public static List<EncryptData> convert(List<EncryptDataDO> entityList){
		if(CollectionUtils.isEmpty(entityList)){
			return new ArrayList<EncryptData>();
		}
		List<EncryptData> resultList = new ArrayList<EncryptData>();
		for(EncryptDataDO entity : entityList){
			resultList.add(UesConverter.convert(entity));
		}
		return resultList;
	}

	public static DataHashDO convert(DataHash from){
		if(from == null){
			return null;
		}
		DataHashDO to = new DataHashDO();
		to.setCreateTime(from.getCreateTime());
		to.setHash(from.getHash());
		to.setId(from.getId());
		to.setTicket(from.getTicket());
		to.setUpdateTime(from.getUpdateTime());
		return to;
	}
	
	public static DataHash convert(DataHashDO from){
		if(from == null){
			return null;
		}
		DataHash to = new DataHash();
		to.setCreateTime(from.getCreateTime());
		to.setHash(from.getHash());
		to.setId(from.getId());
		to.setTicket(from.getTicket());
		to.setUpdateTime(from.getUpdateTime());
		return to;
	}
}